import log from '@dfeidao/atom-nodejs/logger/log';
import { IncomingHttpHeaders } from 'http';
import query from '@dfeidao/atom-nodejs/db/query';
import { systemid, productid } from '../../atom/config';
import count from '@dfeidao/atom-nodejs/db/count';
interface Message {
	page_no: number,
	post_package: string,

}

// interface IWebResult {
// 	data: unknown;
// 	cookie?: {
// 		[name: string]: string;
// 	} | null;
// 	content_type?: string;
// 	headers?: {
// 		[key: string]: string[];
// 	};
// 	attachment?: string;
// 	redirect?: string;
// 	status_code?: number;
// }

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
	const d = query(action_id, session_id, systemid);

	d.prepare('asso_job', ['post_package', 'post_no', 'post_name', 'productid'], { productid, post_package: message.post_package }
		, 5, message.page_no, [], []);
	const res = await d.exec();
	const data = res[0];

	const { prepare: p, exec } = count(action_id, session_id, systemid)
	p('asso_job', { productid, post_package: message.post_package })
	const [x] = await exec();

	return {
		data: { data, x }
	}
}
